<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<style type="text/css">
	label.col-2{width: 120px;}
	.models i{font-size: 16px;}

	#tuan{
		background-color: #f2dede;
	    padding: 10px;
	    border-radius: 10px;
	}
	
	
	/*缩略图展示*/
	.uploader-blank{padding-top: 15px; width:158px;}
	.uploader-list{margin-bottom: 3px; position: relative;}
	.uploader-list img{height: 100px; width: 145px; border:#ccc 1px solid; padding: 3px;}
	.uploader-list .item{display: inline-block; text-align: center; position: relative; width: 157px;}
	.uploader-list .item .pic-box{border: #f0ecec 1px solid;}
	.uploader-list .item .state{position: absolute; bottom: -8px; text-align: center; background-color: #000; opacity: 0.6; color: #fff; padding: 1% 5%; width: 90%; overflow: hidden;}
	#filePicker{float: inherit;}

	/*附件列表*/
	.fujian{display: inline-block; width: auto; position: relative;
    padding-right: 20px;}
    .fujian i.mediadel{
    font-size: 25px;
    position: absolute;
    top: 0px;
    line-height: 25px;
    display: inline-block;
    cursor: pointer;
    }
	.fujian li{list-style: none;  float: left; margin-right: 30px; position: relative; }
	.fujian li img{height: 100px;
    width: 100px;
    border: #ccc 1px solid;
    padding: 3px;}
	.fujian li i{ font-size: 22px;
    position: absolute;
    cursor: pointer;
    right: -7px;
    top: -12px;}
	.fujian li p{font-size: 12px; margin-left: 3px; line-height: 30px;}
	.fujianadd{
		    font-size: 100px;
    float: left;
    line-height: 92px;
	}
	
	
	#slimg{position: absolute; bottom: 0px; left: 0px; width: 100%; height: 30px;}

	.caozuo{}
	.caozuo span{cursor: pointer; margin-right: 10px;}
	#tpl_blank{position: relative; width: 230px;}
	.inputblank{position: absolute; display: none;
    width: 100%;
    height: 100%;
    top: 0px;
    background-color: #fff;}
	#tpl_blank span{margin-right: 5px;}
	.inputtplid{
		width: 90px; margin-right: 5px;
	}
	.inputtplid input{
		width: 90px;
	}
	.guige{background-color:#f9f9f9; border-radius: 3px;}
	.guige tr{border:#ddd 1px solid; list-style: none; padding: 5px 10px; padding: 0px; position: relative;}
	.guige td{padding: 5px 10px;}

	.guige td.text{width: 80px; text-align: center; border-right: #ddd 1px solid;}
	.guige td.del{width: 25px; cursor: pointer;}
	.guige td.input{}
	.guige i{
	    font-size: 25px;
    	line-height: 20px;
	}

	.models{background-color:#f9f9f9; border-radius: 3px;}
	.models tr{border:#ddd 1px solid; list-style: none; padding: 5px 10px; padding: 0px; position: relative;}
	.models td{padding: 5px 10px;}
	.models td.text{min-width: 100px; text-align: center; border-right: #ddd 1px solid;}
	.models td.text img{width: 30px; height: 30px;}

	.models td.text label{width: 100%; display:inline-block;}
	.models td.model-del{text-align: center; padding: 0; cursor: pointer; width: 50px; padding: 0 5px;}
	.models td.input{}


	
	#tuanservice label{
		margin-right: 10px;
	}

	
</style>
<title>产品编辑</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form1">
		<input type="hidden" name="store_id" value='' id="store_id">
		<input type="hidden" name="transport_id" id="transport_id">
		<input type="hidden" name="ad_goods_id" id="ad_goods_id">

		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>产品名称：</label>
			<div class="formControls col-4">
				<input type="text" class="input-text" value="" placeholder="" id="goods_name" name="goods_name" nullmsg="产品名称不能为空！" datatype="s1-100">
			</div>
			<div class="col-2"> </div>
			<!-- <div class="col-2"  id="tpl_blank"> 
				<span class="select-box">
					<select name="tpl_goods" id="tpl_goods" class="select">
						<option value="" selected="">使用申请信息填写</option>
						<option value='0'>输入申请信息id</option>
					</select>
				</span> 
				<div class="inputblank">
					<span class="inputtplid"><input type="text" class="input-text" value="" placeholder="输入商品id" id="tpl_id" name="tpl_id"></span>
					<span><div class="btn btn-secondary-outline radius" id="btn-searchtpl">确定</div></span>
					<span><div class="btn btn-secondary-outline radius" id="btn-backtpl">返回</div></span>
				</div>
			</div> -->
			
		</div>
		<div class="row cl">
			<label class="form-label col-2">副标题：</label>
			<div class="formControls col-6">
				<input type="text" class="input-text" value="" placeholder="" id="goods_brief" name="goods_brief">
			</div>
			<div class="col-2"> </div>
			
		</div>
		
		<div class="row cl">
			<label class="form-label col-2">U币抵扣：</label>
			<div class="formControls col-6">
				<input type="text" class="input-text" value="" placeholder="" id="goods_max_u" name="goods_max_u">
			</div>
			<div class="col-2"> </div>
			
		</div>

		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>售价：</label>
			<div class="formControls col-1">
				<input type="number" step="1" class="input-text" value="" placeholder="" id="goods_cost" name="goods_cost" nullmsg="原价不能为空！" datatype="s1-100">
			</div>		
			<div class="col-1"></div>

			<label class="form-label col-1"><span class="c-red">*</span>成本价：</label>
			<div class="formControls col-1">
				<input type="number" step="1" class="input-text" value="" placeholder="" id="goods_account" name="goods_account" nullmsg="成本价不能为空！" datatype="s1-100">
			</div>		
			<div class="col-1"></div>

			
			


			<label class="form-label col-1"><span class="c-red">*</span>重量：</label>
			<div class="formControls col-1">
				<input type="number" class="input-text" value="" placeholder="单位：克" id="goods_weight" name="goods_weight" nullmsg="重量不能为空！" datatype="n1-100">克
			</div>
			<div class="col-1"></div>
			<label class="form-label col-1">排序：</label>
			<div class="formControls col-1">
				<input type="number" class="input-text" value="" placeholder="" id="goods_sort" name="goods_sort">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>栏目：</label>
			<div class="formControls col-1"> 
				<span class="select-box">
					<select name="gc_id1" id="gc_id1" class="select" >
						<option value="" selected="">全部分类</option>
					</select>
				</span> 
			</div>
			<div class="formControls col-1"> 
				<span class="select-box">
					<select name="gc_id2" id="gc_id2" class="select" >
						<option value="" selected="">全部分类</option>
					</select>
				</span> 
			</div>
			<div class="col-1"> </div>

			<label class="form-label col-2">生产日期：</label>
			<div class="formControls col-3">
				<input class="input-text datainp" id="goods_adddate" type="text" name="goods_adddate" value="" >
				
			</div>
			
		</div>

		
		
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>库存：</label>
			<div class="formControls col-1">
				<input type="text" class="input-text" value="" placeholder="" id="goods_num" name="goods_num" nullmsg="产品数目不能为空！" datatype="s1-100">
			</div>
			<div class="col-1"></div>

			<label class="form-label col-1"><span class="c-red">*</span>单位：</label>
			<div class="formControls col-1">
				<input class="input-text" size="1" name="goods_unit" id="goods_unit" placeholder="包" nullmsg="产品单位不能为空！" datatype="s1-1">
			</div>
			<div class="col-1"></div>
			<label class="form-label col-1">销量：</label>
			<div class="formControls col-1">
				<input class="input-text" size="1" name="goods_sales" id="goods_sales" disabled="disabled">
			</div>
			<div class="col-1"></div>
			
		</div>




		<div class="row cl" >
			<label class="form-label col-2"></label>
			<div class="formControls col-3" ></div>
		</div>


		

		<div class="row cl">
			<label class="form-label col-2">参数：</label>
			<div class="formControls col-2"><input type="text" class="input-text" value="" placeholder="" id="goods_guige_title"></div>
			<div class="formControls col-4 guige">

					<input type="text" class="input-text" value="" placeholder="" id="goods_guige_value">
					<input type="hidden" name="goods_spec" id="goods_spec">

			</div>
			<div class="btn btn-secondary-outline radius col-2" id="guige-add">添加</div>
		</div>

		<div class="row cl">
			<label class="form-label col-2">示例：</label>
			<div class="formControls col-6">
				<table class="guige">
					<tr><td class="text">☆☆☆颜色☆☆☆：</td><td class="input">红色</td></tr>
				</table>
				
			</div>	
		</div>
		<div class="row cl">
			<label class="form-label col-2"></label>
			<div class="formControls col-6">
				<table class="guige" id="guige-list">
					<!-- <li><span class="text">颜色：</span><span class="input"><input type="text" name="" class="input-text"></span></li> -->
				</table>
				
			</div>	
		</div>


		<div class="row cl">
			<label class="form-label col-2">多规格：</label>
			<div class="formControls col-6">
				
				<table class="models">
					<tr>
						<td class="text" id="guigeid">规格id</td>
						<td class="text">规格名称</td>
						<td class="text">规格图片</td>
						<td class="text">库存</td>
						<td class="text">价格</td>
						<!-- <td class="text">团购价格</td> -->
						<td class="text">重量</td>
						<!-- <td class="text">抵扣券</td> -->
						<!-- <td class="text">预售数量</td> -->
						<td class="text">是否启用</td>
						<td class="model-del" >
							
							<div class="btn btn-secondary-outline radius" id="model-add">添加</div>
						</td>

					</tr>
					
				</table>
			</div>
			<div class="formControls col-2"></div>
			<!-- <div class="formControls col-1 btn btn-secondary-outline radius col-2" >添加</div>	 -->
		</div>
		<div class="row cl" style="margin-top: 1px;">
			<label class="form-label col-2"></label>
			<div class="formControls col-6">
				<table class="models" id="model-list">
					<!-- <tr><td class="text">'+model_1+'</td><td class="text">'+model_2+'</td><td class="text">'+model_3+'</td><td class="model-del"><i class="icon Hui-iconfont" data-id="1"></i><input type="hidden" name="goods_sku" value="'+inputvalue+'"></td></tr> -->
				</table>
				
			</div>	
		</div>
		<div class="row cl">
			<label class="form-label col-2">开启团购：</label>
			<div class="formControls col-6">
				<div class="radio-box">
					<label><input type="radio" value="1" name="is_group">是</label>
				</div>
				<div class="radio-box">
					<label><input type="radio" value="0" name="is_group" checked="">否</label>
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">开启秒杀：</label>
			<div class="formControls col-6">
				<div class="radio-box">
					<label><input type="radio" value="1" name="is_seckill">是</label>
				</div>
				<div class="radio-box">
					<label><input type="radio" value="0" name="is_seckill" checked="">否</label>
				</div>
				<table class="models" id="seckill-list" style="display: none;">
					<tbody>
						<tr>
							<td class="text">秒杀价格</td>
							<td class="text">开始时间</td>
							<td class="text">结束时间</td>
						</tr>
						<tr id="seckill466">
							<td class="text"><input type="number" class="input-text" id="seckill_cost" name="seckill_cost" ></td>
							<td class="text"><input type="text" class="input-text" id="add_time" name="add_time" ></td>
							<td class="text"><input type="text" class="input-text" id="end_time" name="end_time" ></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>

<!-- 		<div class="row cl">
			<label class="form-label col-2">服务说明：</label>
			<div class="formControls col-6" id="tuanservice">
				
			</div>	
		</div> -->

		

<!-- 		<div class="row cl">
			<label class="form-label col-2">是否团购</label>
			<div class="formControls col-3 s-msg">
			    <div class="radio-box">			        
			        <label class="lh-26"><input type="radio" name="is_group" value="1">是</label>
			    </div>
			    <div class="radio-box">
			        <label class="lh-26"><input type="radio" name="is_group" value="0" checked>否</label>
			     </div>
			</div>		
		</div>	 -->

		


<!-- 		<div style="display: none;" id="tuan">
			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>开团时间：</label>
				<div class="formControls col-3">
					<input type="text" id="group_time" name="group_time" class="input-text datainp">
				</div>
				<label class="form-label col-1">单独购买：</label>
				<div class="formControls col-2">
				    <div class="radio-box">			        
				        <label class="lh-26"><input type="radio" name="is_group_buy_only" value="1">允许</label>
				    </div>
				    <div class="radio-box">
				        <label class="lh-26"><input type="radio" name="is_group_buy_only" value="0" checked>不允许</label>
				     </div>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">团购钱数：</label>
				<div class="formControls col-1">
					<input type="text" class="input-text" value="" placeholder="" id="group_cost" name="group_cost">
				</div>
				<label class="form-label col-1">团购人数：</label>
				<div class="formControls col-1">
					<input type="text" class="input-text" value="" placeholder="" id="group_people" name="group_people">
				</div>
				<label class="form-label col-1">虚拟销量：</label>
				<div class="formControls col-1">
					<input type="text" class="input-text" value="" placeholder="" id="group_sales2" name="group_sales2">
				</div>

				
				
			</div>
			
			
			<div class="row cl">
				<label class="form-label col-2">团购规则详情：</label>
				<div class="formControls col-10">
					<textarea name="group_rule" id="group_rule" cols="" rows="" class="textarea"  placeholder="团购规则详情..." ></textarea>
					<p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p>
				</div>
			</div>
		</div> -->



		

		

		

<!-- 		<div class="row cl">
			<label class="form-label col-2" style="color: #f37b1d;">是否推广</label>
			<div class="formControls col-3 s-msg">
			    <div class="radio-box">
			        <label class="lh-26">
			        	<input type="radio" name="is_extend" value="1" >是
			        </label>
			    </div>
			    <div class="radio-box">
			        <label class="lh-26">
			        	<input type="radio" name="is_extend" value="0" checked>否
			        </label>
			     </div>
			</div>		
		</div>	 -->

		




			
		<div class="row cl">
			<label class="form-label col-2">宝贝音频：</label>
			<div class="formControls col-10" >				
				<span class="l mb-10 fujian" id="fujian2" style="display: block;">
					<!-- <audio controls=true><source src="http://img3.muyoudaoli.com/unravel.mp3" /></audio> -->
				</span>
				<i class="btn btn-secondary radius" style="margin-left: 10px" onclick="_open('上传音频','article-imageupload.html?type=audio&idname=fujian2&api=voice&single=1&inputname=voice','90%','90%',true)">上传音频</i>				
				<i>支持音频格式：mp3(10M以内)</i>		
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-2">宝贝视频：</label>
			<div class="formControls col-10" >				
				<span class="l mb-10 fujian" id="fujian3" style="display: block;">
					<!-- <audio controls=true><source src="http://img3.muyoudaoli.com/unravel.mp3" /></audio> -->
				</span>
				<i class="btn btn-success radius" style="margin-left: 10px" onclick="_open('上传音频','article-imageupload.html?type=video&idname=fujian3&api=video&single=1&inputname=video','90%','90%',true)">上传视频</i>				
				<i>支持视频格式：mp4(10M以内)</i>		
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-2">产品图片：</label>
			<div class="formControls col-10" >
				
				<span class="l mb-10 fujian" id="fujian">
					<!-- <li><img src="/Upload/article/4/5721763bd1d88.jpg"><i class="Hui-iconfont" onclick="fj_close(this);">&#xe706;</i></li> -->
				</span>
				<i class="Hui-iconfont fujianadd" onclick="_open('添加附件','article-imageupload.html?type=image&idname=fujian&api=goods&single=0&inputname=goods_images2','90%','90%',true)">&#xe610;</i>


				<!-- <a id="btn-img" class="btn btn-secondary radius ml-10" onclick="_open('添加附件','article-imageupload.html?type=file&idname=fujian&api=goods&single=0&inputname=goods_images','750px','470px',true)">选择附 件</a>-->
	
				
	
			</div>
		</div>
		
		
		<div class="row cl">
			<label class="form-label col-2">文章内容：</label>
			<div class="formControls col-10"> 
				<script id="editor" name="goods_info" type="text/plain" ></script> 
			</div>
        </div>
        
        <!-- 查看大图 -->
        <div class="cha_img hide" id="max_img_bg">
            <div class="pic-viewer-wrap">
                <div class="cha-img-nei">
                </div>
            </div>
            <div class="cha-img-close" onclick="$('#max_img_bg').addClass('hide')"><img src="./images/close.png"></div>
        </div>
		

		
</div>

<div class="row cl pr-20" style="position:fixed; bottom:10px; width: 200px; right: 10px; text-align: right; z-index:1000; ">
	
		<button class="btn btn-primary radius" type="button" id="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
		<button onClick="removeIframe();" class="btn btn-default radius" type="button" style="margin-left:10px;">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
	
</div>
</form>

<script type="text/javascript" src="lib/layer/2.1/layer.js"></script> 

<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script> 
<script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.config.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.all.min.js"> </script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script> 
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script> 
<script type="text/javascript" src="js/template-native.js"></script> 
<script type="text/javascript" src="js/s.js"></script> 

<script type="text/javascript" src="lib/daterangepicker/moment.min.js"></script> 
<script type="text/javascript" src="lib/daterangepicker/jquery.daterangepicker.js"></script>
<link rel="stylesheet" href="lib/daterangepicker/daterangepicker.css" /> 


<script type="text/javascript">

    $(document).on('click','.pic-thumb',function () {
        var path = $(this).attr('src');
        var html_img = "<img src='"+path+"'/>";
        $("#max_img_bg").find('.cha-img-nei').html(html_img);
        $("#max_img_bg").removeClass('hide');
    });


var gc_id1,gc_id2;//分类
var service=[];

$("#form1").attr("action", API_GOODS); 
var editid=getUrlParam('editid');//编辑菜单id

// 商家列表
function getshops(id,key){
	var api=API_SHOP;
	if(key){
		api=API_SHOP+'?k='+key;
	}
	var html="";
	$.getJSON(api,function(data){
        if(!checkStatus(data)) return;
        for (x in data.datas){
            html+="<li data-name="+data.datas[x].store_name+" data-id="+data.datas[x].store_id+">"+data.datas[x].store_id+": "+data.datas[x].store_name+"</li>";
        }
        id.html(html);
    }); 
}
// 运费模板列表
function gettranselist(id,key){
	var api=API_TRANSTMP;
	if(key){
		api=API_TRANSTMP+'?k='+key;
	}
	var html="";
	$.getJSON(api,function(data){
        if(!checkStatus(data)) return;
        for (x in data.datas){
            html+="<li data-name="+data.datas[x].title+" data-id="+data.datas[x].id+">"+data.datas[x].id+": "+data.datas[x].title+"</li>";
        }
        id.html(html);
    }); 
}
// 广告列表
// 运费模板列表
function getads(id,key){
	var api=API_PRODUCTAD;
	if(key){
		api=API_PRODUCTAD+'?k='+key;
	}
	var html="";
	$.getJSON(api,function(data){
        if(!checkStatus(data)) return;
        for (x in data.datas){
            html+="<li data-name="+data.datas[x].goods_name+" data-id="+data.datas[x].ad_goods_id+">"+data.datas[x].ad_goods_id+": "+data.datas[x].goods_name+"</li>";
        }
        id.html(html);
    }); 
}






// 添加参数
var index=1;
$(document).on('click','div#guige-add',function(){

	var title=$("#goods_guige_title").val();
	var value=$("#goods_guige_value").val();
	var save=$("#goods_spec").val();
	if(title.replace(/\s/g, "").length==0 || value.replace(/\s/g, "").length==0){
		layer.msg("请填写参数内容", {icon:2,time:1000});
		return;
	}
	if(save.replace(/(^\s+)|(\s+$)/g, "").length>0){
		save=JSON.parse(save);

	}else{
		save=[];
	}
	save=save.concat([{index:index,title:title,value:value}]);	
	$("#guige-list").append('<tr><td class="text">'+title+'</td><td class="input">'+value+'</td><td class="del"><i class="icon Hui-iconfont" data-id='+index+'>&#xe60b;</i></td></tr>');
	save=JSON.stringify(save); 
	$("#goods_spec").val(save);
	index++;
	$("#goods_guige_title").val("");
	$("#goods_guige_value").val("");
})
// 删除参数
$(document).on('click','#guige-list td.del i',function(){
	var index=$(this).data("id");

	var string=$("#goods_spec").val();
	var list=JSON.parse(string);
	var that=$(this);
	for(k in list){
		if(list[k].index==index){
			that.parent().parent("tr").remove();
			list.splice(k,1);
			list=JSON.stringify(list); 
			$("#goods_spec").val(list);
		}
	}
})

function editguige(guigeid,goodid){
	_open('修改规格','product-guige-add.html?editid='+guigeid+'&gid='+goodid,'50%','80%',true)
}

// 添加规格
var model_index=1;
$(document).on('click','div#model-add',function(){
	_open('添加规格','product-guige-add.html?gid='+editid,'50%','80%',true)
})

$(document).on('click','div#seckill-add',function(){
	_open('添加秒杀','product-seckill-add.html?gid='+editid,'50%','80%',true)
})




// 删除音频视频
$(document).on('click','i.mediadel',function(){
	var type=$(this).data("type");
	$(this).closest("span.fujian").html('<input type="hidden" name="'+type+'" value="">');
})

function removeIframe(){
	var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}



function sortchange(){
	var strvalue=$("#sort").val();
	$("#selectsort").text("/"+strvalue);
}
// 获取商品信息
function getgoodsinfo(id){
	$.getJSON(API_APPLYLIST+"?aid="+id,function(data){
		if(!checkStatus(data)) return;
		if(data.datas==null || data.datas==""){
			layer.msg("商品不存在", {icon:2,time:1000});
			return;
		}
        $("#goods_name").val(data.datas.goods_name);
        $("#goods_brief").val(data.datas.goods_brief); 
        $("#address").val(data.datas.address);
        
        $("#goods_num").val(data.datas.goods_num);
        $("#goods_unit").val(data.datas.goods_unit);
        $("#goods_adddate").val(data.datas.goods_adddate);
 


        var goods_images=data.datas.goods_images;
        $('#fujian').html("");
    	for (x in goods_images){

    		$('#fujian').show();
    	   	$('#fujian').append('<li><img src="'+getIcon(goods_images[x])+'"><i class="Hui-iconfont" onclick="fj_close(this);">&#xe706;</i><input type="hidden" name="goods_images2['+x+']" value="'+goods_images[x]+'"></li>');	
    	} 
        gc_id1=  data.datas.gc_id1; //分类1
        gc_id2=  data.datas.gc_id2; //分类2
     	
        // 更新分类
        getclass(gc_id1,gc_id2);

        UE.getEditor('editor').addListener('ready', function (editor) {
            UE.getEditor('editor').setContent(data.datas.goods_info);
        });


        $("input[name='goods_show'][value="+data.datas.goods_show+"]").attr("checked",true);

        

	})
}
	// 分类列表
	function getclass(id1,id2){
		var gc;
		var id1=id1 || 0;
		var id2=id2 || 0;
		$.getJSON(API_GOODSCLASS,function(data){
			if(!checkStatus(data)) return;

			gc=data.datas;
			var index;
		    if(data==''){
		    	layer.msg('分类出错', {icon:5,time:1000});
		    }else{
		    	// 罗列一级分类
		    	for(i=0; i<data.datas.length; i++){
		    
		    		if(id1==data.datas[i].gc_id){
		    			$("#gc_id1").append("<option value='"+data.datas[i].gc_id+"' data-flag='"+i+"' selected>"+data.datas[i].gc_name+"</option>");
		    			if(data.datas[i].child){
		    				for(j=0; j<data.datas[i].child.length; j++){
		    					if(id2==data.datas[i].child[j].gc_id){
		    						$("#gc_id2").append("<option value='"+data.datas[i].child[j].gc_id+"' data-flag='"+i+"' selected>"+data.datas[i].child[j].gc_name+"</option>");
		    					}else{
		    						$("#gc_id2").append("<option value='"+data.datas[i].child[j].gc_id+"' data-flag='"+i+"'>"+data.datas[i].child[j].gc_name+"</option>");
		    					}
		    					
		    				}
		    			}
		    			
		    		}else{
		    			$("#gc_id1").append("<option value='"+data.datas[i].gc_id+"' data-flag='"+i+"'>"+data.datas[i].gc_name+"</option>");
		    		}

		    		
		    	}
		    	//二级菜单联动
		    	$("#gc_id1").change(function () {


		    		var ii=$('#gc_id1 option:selected').data("flag");
		    		if(gc[ii]['child']){
    					var data2=gc[ii]['child'];
    						$("#gc_id2").empty();
    						$("#gc_id2").append("<option value='0' >全部分类</option>");
    					for(j=0; j<data2.length; j++){
    			    		$("#gc_id2").append("<option value='"+data2[j].gc_id+"' >"+data2[j].gc_name+"</option>");
    			    	}
		    		}
		    		
		    	});
		    } 	
		});
	}


$(function(){

	

	$('input[name=is_seckill]').on('change',function (){
		$(this).val() == 1 ? $('#seckill-list').show() : $('#seckill-list').hide();
	})

	




	// 获取申请列表
	// var tplgoodslist=new Array();
	// $.getJSON(API_APPLYLIST+"?p=1",function(data){
	//     if(!checkStatus(data)) return;
	//     tplgoodslist=tplgoodslist.concat(data.datas);
	//     $.getJSON(API_APPLYLIST+"?p=2",function(data){
	// 	    if(!checkStatus(data)) return;
	// 	    tplgoodslist=tplgoodslist.concat(data.datas);
	// 	    for(i=0; i<tplgoodslist.length; i++){
	// 		   	$("#tpl_goods").append("<option value='"+tplgoodslist[i].apply_id+"'>"+tplgoodslist[i].apply_id+":"+tplgoodslist[i].goods_name+"</option>");
	// 		}
	// 	})
	// })
	


	
	// 选择商品事件
	// $("#tpl_goods").bind("change",function(){
	// 	var id=$(this).val();
	// 	if(id=="" || id==null || id==undefined){
	// 		layer.msg("请选择申请商品", {icon:2,time:1000});
	// 		return;
	// 	}
	// 	if(id==0){
	// 		$(".inputblank").show();
	// 		$(document).on('click','div#btn-searchtpl',function(){
	// 			var inputid=$("#tpl_id").val();
	// 			if (typeof(parseInt(inputid)) !== "number"){
	// 				layer.msg("正确输入商品id", {icon:2,time:1000});
	// 			}else{
	// 				getgoodsinfo(inputid);
	// 			}
	// 		})
	// 		$(document).on('click','div#btn-backtpl',function(){
	// 			$(".inputblank").hide();
	// 			$("#tpl_goods").val("");
	// 		})
	// 	}else{
	// 		getgoodsinfo(id);
	// 	}
	// })

	// $("input[name=is_extend]").change(function(){
	// 	var value=$(this).val();
	// 	if(value==1){
	// 		$("#ad_address").show();
	// 	}else{
	// 		$("#ad_address").hide();
	// 	}
	// })
	

	$('#goods_adddate').dateRangePicker(
	{
		autoClose: true,
		singleDate : true,
		showShortcuts: false,
		singleMonth: true,


		startOfWeek: 'monday',
		format: 'YYYY-MM-DD HH:mm:ss',
		time: {
			enabled: true
		},
		defaultTime: moment().startOf('day').toDate(),
		defaultEndTime: moment().endOf('day').toDate(),

	});
	$('#add_time').dateRangePicker({
		autoClose: true,
		singleDate : true,
		singleMonth: true,
		showShortcuts: false,
		startOfWeek: 'monday',
		format: 'YYYY-MM-DD HH:mm:ss',
		time: {
			enabled: true
		},
		defaultTime: moment().startOf('day').toDate(),
		defaultEndTime: moment().endOf('day').toDate(),
	});
	$('#end_time').dateRangePicker({
		autoClose: true,
		singleDate : true,
		singleMonth: true,
		showShortcuts: false,
		startOfWeek: 'monday',
		format: 'YYYY-MM-DD HH:mm:ss',
		time: {
			enabled: true
		},
		defaultTime: moment().startOf('day').toDate(),
		defaultEndTime: moment().endOf('day').toDate(),
	});
	// $('#group_time').dateRangePicker(
	// {
	// 	startOfWeek: 'monday',
	// 	separator : ' to ',
	// 	format: 'YYYY-MM-DD HH:mm',
	// 	autoClose: true,
	// 	time: {
	// 		enabled: true
	// 	},
	// 	defaultTime: moment().startOf('day').toDate(),
	// 	defaultEndTime: moment().endOf('day').toDate()
	// });


	

	// 商品操作、审核/确认收货
	$(document).on('click','span.pagefun-shenhe',function(){
	    var id=editid;
	    var that=$(this);
	    var flag=that.data("flag");
	    $.getJSON(API_GOODS,{pending:id,t1:flag},function(data){
	    	checkStatus(data);
	        if(data.status==1){
	        	if(flag==1){
	        		that.parent().html("审核通过");
	        	}else if(flag==0){
	        		that.parent().html("审核不通过");
	        	}
	        	
            }
	    });  
	})


	// 添加时规格状态选择
	$(document).on('click',"input.selectskustate",function(){
		if($(this).prop("checked")){
			$(this).closest("label").find("input[name='sku_state[]']").val("1")
		}else{
			$(this).closest("label").find("input[name='sku_state[]']").val("0")
		}
	})
	// 编辑时规格状态选择
	$(document).on('click',"input.editselectskustate",function(){
		var value;
		var id=$(this).closest("tr").find("td:first-child").html();
		// console.log("id")
		$(this).prop("checked")?value=1:value=0;
		$(this).closest("label").find("input[name='sku_state[]']").val(value);
		console.log(id);
		$.post(API_GUIGE_EDIT+'?sku_id='+id,{
			sku_state:value,
		},function(data){
		    if(!checkStatus(data)) return;
		    layer.closeAll('loading');
		    layer.msg("操作成功", {icon:1,time:1000});
		},'json')
	})



	// 商品修改
	if(editid!==null){	     
	    var eidturl=API_GOODS+"?id="+editid;
	    // 读取即将编辑的文章信息
	    $.getJSON(eidturl,function(data){

	    	if(!checkStatus(data)) return;//判断登录

	    	if(data.datas==''){
	    		layer.msg("数据加载错误", {icon:2,time:1000});
	    	}else{
	            $("#goods_name").val(data.datas.goods_name);
	            $("#goods_brief").val(data.datas.goods_brief);
				$("#goods_max_u").val(data.datas.goods_max_u);

	            $("#address").val(data.datas.address);
	            
	            $("#goods_sales").val(data.datas.goods_sales);

	            $("#goods_num").val(data.datas.goods_num);
	            $("#goods_sort").val(data.datas.goods_sort);
	            $("#group_rule").val(data.datas.group_rule);
	            if(data.datas.group_addtime!=="1970-01-01 08:00:00" && data.datas.group_endtime!=="1970-01-01 08:00:00"){
	            	$("#group_time").val(data.datas.group_addtime+' to '+data.datas.group_endtime);
	            }

	            $("#group_cost").val(data.datas.group_cost);
	            $("#group_people").val(data.datas.group_people);
	            $("#group_sales2").val(data.datas.group_sales2);
	            


	             
	            
	            

	            // $("input[name='is_extend'][value="+data.datas.is_extend+"]").attr("checked",true);
	            
	            $("input[name='is_group'][value="+data.datas.is_group+"]").attr("checked",true);
	            $("input[name='is_group_buy_only'][value="+data.datas.is_group_buy_only+"]").attr("checked",true);


	            
	            

	            
	            // if(data.datas.is_extend==1){
	            // 	$("#ad_address").show();
	            // 	$("#ad_goods_id").val(data.datas.ad_goods_id);
	            // 	$("input[data-type=ad]").val(data.datas.ad_goods_name);
	            // }

	            // 团购
	            // if(data.datas.is_group==1){
	            // 	$("#tuan").show();
	            // }
	           

	            // 服务
	   //          var ids=data.datas.group_ensure;
    //         	$.getJSON(API_TUANSERVICE,function(data2){
				// 	if(!checkStatus(data2)) return;
				// 	for(i=0; i<data2.datas.length; i++){
				// 		if(ids.split(",").indexOf(data2.datas[i].ensure_id.toString())>-1){
				// 			$("#tuanservice").append('<label><input type="checkbox" name="group_ensure[]" value="'+data2.datas[i].ensure_id+'" checked>'+data2.datas[i].ensure_name+'</label>')
				// 		}else{
				// 			$("#tuanservice").append('<label><input type="checkbox" name="group_ensure[]" value="'+data2.datas[i].ensure_id+'">'+data2.datas[i].ensure_name+'</label>')
				// 		}
				// 	}	
				// })
	            
                	

	            
	            $("#goods_unit").val(data.datas.goods_unit);
	            $("#goods_weight").val(data.datas.goods_weight);
	            $("#goods_cost").val(data.datas.goods_cost);
	            $("#goods_account").val(data.datas.goods_account);

	            

	            $("#goods_adddate").val(data.datas.goods_adddate);
	            $("#form1").attr("action", eidturl);
	            var transport_id=data.datas.transport_id;
	            
	            var list=data.datas.goods_spec;
	            $("#goods_spec").val(list);
	            if(list!==""){
	            	list=JSON.parse(list);
	            	for(j in list){
		            	$("#guige-list").append('<tr><td class="text">'+list[j].title+'</td><td class="input">'+list[j].value+'</td><td class="del"><i class="icon Hui-iconfont" data-id='+list[j].index+'>&#xe60b;</i></td></tr>');
		            }
	            }

	            // 规格
                var goods_sku=data.datas.goods_sku;
                $("#guigeid").show();
                if(goods_sku && goods_sku.length>0){
                	$("#model-list").empty();
                	for(var j in goods_sku){
                		var sku_state=goods_sku[j].sku_state==1?'checked':'';
                		
    	            	

    	            	$("#model-list").append('<tr id="sku'+goods_sku[j].sku_id+'"><td class="text">'+goods_sku[j].sku_id+'</td><td class="text">'+goods_sku[j].sku_info+'</td><td class="text"><img src="'+goods_sku[j].sku_image+'"></td><td class="text">'+goods_sku[j].sku_num+'</td><td class="text">'+goods_sku[j].sku_cost+'</td><td class="text">'+goods_sku[j].sku_weight+'</td><td class="text"><label><input type="checkbox" class="editselectskustate" value="1" '+sku_state+'>启用<input type="hidden" name="sku_state[]" value="'+goods_sku[j].sku_state+'"></label></td><td><a style="text-decoration:none" onClick="editguige('+goods_sku[j].sku_id+','+editid+')" class="ml-5 edit" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> </td></tr>');
    	            	
    	            }

                	
                }

              
                // 设置商家
                var numshop=0;
                if(data.datas.store_id){
                	var store_id=data.datas.store_id;
    				$.getJSON(API_SHOP,function(shopdata){
    			        if(!checkStatus(data)) return;
    			        if(shopdata.datas.length>0){
    	        	        for(k in shopdata.datas){
    	        	        	if(shopdata.datas[k].store_id==store_id){

    	        	        		$("#store_id").val(shopdata.datas[k].store_id);
    	        					$("input[data-type=shop]").val('id:'+shopdata.datas[k].store_id+' '+shopdata.datas[k].store_name);

    	        	        		
    	        	        		numshop++;
    	        	        		break;
    	        	        	}
    	        	        }
    	        	        if(numshop==shopdata.datas.length){
    	        				layer.msg("该商家已被删除",{icon:5,time:1000});
    	        			}
    			        }  
    			    });
                }
    			 
	            
	            // 设置运费模板
	            var num=0;
				$.getJSON(API_TRANSTMP,function(transdata){
			        if(!checkStatus(data)) return;
			        if(transdata.datas.length>0){
	        	        for(k in transdata.datas){
	        	        	if(transdata.datas[k].id==transport_id){

	        	        		$("#transport_id").val(transdata.datas[k].id);
	        					$("input[data-type=transport]").val('id:'+transdata.datas[k].id+' '+transdata.datas[k].title);

	        	        		
	        	        		num++;
	        	        		break;
	        	        	}
	        	        }
	        	        if(num==transdata.datas.length){
	        				layer.msg("默认运费模板已被删除",{icon:5,time:1000});
	        			}
			        }
			        
			        
			        
			    }); 
	            // 缩略图
	            var goods_images=data.datas.goods_images;
	        	for (x in goods_images){
	        		$('#fujian').show();
	        	   	$('#fujian').append('<li><img class="pic-thumb" src="'+getIcon(goods_images[x])+'"><i class="Hui-iconfont" onclick="fj_close(this);">&#xe706;</i><input type="hidden" name="goods_images2['+x+']" value="'+goods_images[x]+'"></li>');	
	        	}
	        	// 音频
	        	if(data.datas.voice!==""){
	        		$("#fujian2").html('<audio controls=true><source src="'+data.datas.voice+'" /></audio><input type="hidden" name="voice" value="'+data.datas.voice+'"><i class="icon Hui-iconfont mediadel" data-type="voice"></i>')
	        	}

	        	// 视频
	        	if(data.datas.video!==""){
	        		$("#fujian3").html('<video controls="controls" src="'+data.datas.video+'" /></video><input type="hidden" name="video" value="'+data.datas.video+'"><i class="icon Hui-iconfont mediadel" data-type="video"></i>')
	        	}


                
	            gc_id1=  data.datas.gc_id1; //分类1
	            gc_id2=  data.datas.gc_id2; //分类2

	         	getclass(gc_id1,gc_id2);

	            UE.getEditor('editor').addListener('ready', function (editor) {
		            UE.getEditor('editor').setContent(data.datas.goods_info);
	            });

	            


	            $("input[name='goods_show'][value="+data.datas.goods_show+"]").attr("checked",true);

	            

	 
	        }
	    })
	}else{
		// $.getJSON(API_TUANSERVICE,function(data2){
		// 	if(!checkStatus(data2)) return;

		// 	for(i=0; i<data2.datas.length; i++){
		// 		$("#tuanservice").append('<label><input type="checkbox" name="group_ensure[]" value="'+data2.datas[i].ensure_id+'">'+data2.datas[i].ensure_name+'</label>')
		// 	}	
		// })
		// 设置默认运费模板
		$.getJSON(API_TRANSTMP,function(data){

	        if(!checkStatus(data)) return;
	        if(data.datas.length>0){
	        	var defaultid=data.datas[0].id;
	        	var key=0;
	        	for(var i in data.datas){
	        		if(data.datas[i].id==57){
	        			defaultid=57;
	        			key=i;
	        		}
	        	}
	        	
	        	$("#transport_id").val(defaultid);
	        	$("input[data-type=transport]").val('id:'+data.datas[key].id+' '+data.datas[key].title);
	        	
	        }
	        
	    }); 
    	
	    
	    getclass();
	}



	$(document).on('click','#submit',function(){

		if(parseInt($("input[name='goods_account']").val())>parseInt($("input[name='goods_cost']").val())){
			layer.msg("成本价不能大于售价", {icon:2,time:1000});
		}else{
			Validformsubmit("#form1");
			$("#form1").submit();
		}
		
		

	})


	
	
	
	
	// 富文本编辑器
	getueidt()


});


// 移除选中的图片
function fj_close(obj){
	$(obj).parents("li").remove();
}


</script>
</body>
</html>